package com.leo.quartz.entity;

import com.leo.base.AbstractEntity;
import com.leo.quartz.common.lang.RunStatusEnum;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * @author leo
 * @version 1.0
 * @date 2018/09/17 02:26
 */
@Entity
@Table(name = "leo_job",
        uniqueConstraints=@UniqueConstraint(name = "jobKey", columnNames={"job_name", "job_group"}))
public class QuartzJobPO extends AbstractEntity implements Serializable {

    private String jobName;

    private String jobGroup;

    private String jobDesc;

    private String jobClass;

    private JobStatusEnum jobStatus;


    @Basic
    @Column(name = "job_name")
    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    @Basic
    @Column(name = "job_group")
    public String getJobGroup() {
        return jobGroup;
    }

    public void setJobGroup(String jobGroup) {
        this.jobGroup = jobGroup;
    }

    @Basic
    @Column(name = "job_desc")
    public String getJobDesc() {
        return jobDesc;
    }

    public void setJobDesc(String jobDesc) {
        this.jobDesc = jobDesc;
    }

    @Basic
    @Column(name = "job_class")
    public String getJobClass() {
        return jobClass;
    }

    public void setJobClass(String jobClass) {
        this.jobClass = jobClass;
    }

    @Basic
    @Column(name = "job_status")
    @Enumerated
    public JobStatusEnum getJobStatus() {
        return jobStatus;
    }

    public void setJobStatus(JobStatusEnum jobStatus) {
        this.jobStatus = jobStatus;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) { return true; }
        if (o == null || getClass() != o.getClass()) {  return false; }
        QuartzJobPO that = (QuartzJobPO) o;
        return Objects.equals(jobName, that.jobName) &&
                Objects.equals(jobGroup, that.jobGroup) &&
                Objects.equals(jobDesc, that.jobDesc) &&
                Objects.equals(jobClass, that.jobClass) &&
                jobStatus == that.jobStatus ;
    }

    @Override
    public int hashCode() {
        return Objects.hash(jobName, jobGroup, jobDesc, jobClass, jobStatus);
    }

    public enum JobStatusEnum {
        /** 未使用 */
        LIVE,
        /** 使用中 */
        USING,
        /** 过期不在使用 */
        DEPRECATED,
        /** 位置的类型 */
        UN_KNOW;

        public static JobStatusEnum valueOf(int ordinal) {
            if (ordinal < 0 || ordinal >= values().length) {
                return UN_KNOW;
            }
            return values()[ordinal];
        }
    }

}
